<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Insert extends MY_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->lang->load('candidate/insert', $this->session->userdata['user_lang']);
	}
	
	public function index()
	{
		$data = $_POST;
		
		if (missing_field($data, array('firstname', 'lastname', 'email', 'pass')))
		{
			formError($this->lang->line('insert_missingfield'));
		}
		
		if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL))
		{
			formError($this->lang->line('insert_invalidmail'));
		}
		
		$this->load->model('Membership_model', 'member');
		
		if ($this->member->get(array('email' => $data['email'])))
		{
			formError($data['email'] . ' ' . $this->lang->line('insert_mailexists'));
		}
		
		$data['idtype'] = 1;
		
		if ($this->member->insert($data) === false)
		{
		   formError($this->lang-line('global_systemfail'));
		}
		else
		{
			$this->session->set_userdata($data);
			$this->session->set_userdata(array('logged' => true));
		    formRedirect(base_url() . 'candidate');
		}
	}
}

?>